<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ include file="../taglibs.jsp" %>

<s:set id="currentUser" value="#session.currentUser" />
<s:set id="systemConfigs" value="#session.systemConfig" />

<s:set id="isSearch" value="#parameters.isSearch[0]" />
<s:set id="city" value="#parameters.city[0]" />

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><s:text name="FILE.label.title"/></title>
<link rel="stylesheet" type="text/css" href="../../css/style.css" />
<link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
<script type="text/javascript" src="../../scripts/ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="../../scripts/ext/ext-all.js"></script>
<script type="text/javascript" src="../../scripts/ext/locale/ext-lang-${locale}.js"></script>
<script type="text/javascript" src="../../scripts/ext/plugins/dataview/data-view-plugins.js"></script>
<script type="text/javascript">
<!--

Ext.BLANK_IMAGE_URL = '../../scripts/ext/resources/images/default/s.gif';

Ext.namespace('HaiChuan');

Ext.onReady(function(){

    Ext.QuickTips.init();

    HaiChuan.webroot = '${webroot}';

    HaiChuan.isSearch = '${isSearch}';

    HaiChuan.recordsPerPage = parseInt('${systemConfigs.recordsPerPage}') || 10;

    HaiChuan.storeData = new Ext.data.JsonStore({
        url: HaiChuan.webroot + '/ajax/data/listData.do',
        baseParams: {
            isSearch: '${isSearch}'
            ,province: '${province}'
            ,city: '${city}'
            ,beginDate: '${beginDate}'
            ,endDate: '${endDate}'
        },
        totalProperty: 'totalCount',
        root: 'items',
        id: 'id',
        fields: [
            'id', 'name', 'personInCharge', 'contact', 'tel',
            'fax', 'mobile', 'email', 'website', 'address', 'postcode',
            'staffSize', 'license', 'registeredCapital',
            {name:'establishDate', type: 'string', dateFormat:'timestamp'},
            'industryType', 'enterpriseNature', 'businessModel', 'businessArea',
            'customerType', 'telCode', 'province', 'city', 'businessScope',
            'brief', 'legal', 'customerSource', 'sourceUrl', 'country',
            {name:'submitTime', type:'string', dateFormat:'timestamp'},
            {name:'validation', type: 'int'}
        ]
    });

    HaiChuan.gridData = new Ext.grid.GridPanel({
        id: 'list-view',
        store: HaiChuan.storeData,
        autoHeight: true,
        loadMask: true,
        stripeRows: true,
        bodyStyle: 'width:100%',
        viewConfig: {
            forceFit: true
        },
        autoExpandColumn: 'name',

        columns:[{
            id: 'name',
            header: '单位名称',
            dataIndex: 'name',
            width: 100,
            renderer: function(value, p, record){
                return String.format('{0}', value);
            },
            sortable: true
        },{
            header: '负责人',
            dataIndex: 'personInCharge',
            width: 40,
            sortable: false
        },{
            header: '联系人',
            dataIndex: 'contact',
            width: 40,
            sortable: false
        },{
            header: '电话',
            dataIndex: 'tel',
            width: 50,
            sortable: false
        },{
            header: '传真',
            dataIndex: 'fax',
            width: 50,
            sortable: false
        },{
            header: '移动电话',
            dataIndex: 'mobile',
            width: 60,
            sortable: false
        },{
            header: '电子邮件',
            dataIndex: 'email',
            width: 60,
            sortable: false
        },{
            header: '地区',
            dataIndex: 'city',
            width: 60,
            renderer: function(value, p, record){
                return String.format('{1} {0}', value==null?"":value, record.data.province==null?"":record.data.province);
            },
            sortable: false
        },{
            header: '数据完整度',
            dataIndex: 'validation',
            width: 50,
            renderer: function(value, p, record){
                var v;
                if (value == 1) v = '非常好';
                else if (value == 2) v = '很好';
                else if (value == 3) v = '稍差';
                return String.format('{0}', v);
            },
            sortable: true
        }]
    });

    HaiChuan.pagingToolbarData = new Ext.PagingToolbar({
        pageSize: HaiChuan.recordsPerPage,
        width: 440,
        store: HaiChuan.storeData,
        displayInfo: true,
        displayMsg: '<s:text name="FILE.label.document.pagingToolbar.displayMsg"/>',
        emptyMsg: '<s:text name="FILE.label.document.pagingToolbar.emptyMsg"/>'
    });

    HaiChuan.panelData = new Ext.Panel({
        id: 'data-view',
        frame: false,
        autoHeight: true,
        layout: 'card',
        activeItem: 0,
        items: [HaiChuan.gridData],
        bbar: HaiChuan.pagingToolbarData
    });

    <s:if test="'searchData' in #currentUser.permissions">
    HaiChuan.searchData = new Ext.Panel({
        renderTo: 'search-div',
        frame: false,

        bbar: [
            {
                xtype: 'hidden',
                id : 'isSearch',
                name: 'isSearch',
                value: true
            },
            '地区: ',
            {
                xtype: 'textfield',
                id : 'city',
                name: 'city',
                width: 160
            },
            ' ',
            '数目: ',
            {
                xtype: 'numberfield',
                id : 'count',
                name: 'count',
                width: 60
            },
            ' ',
            '完整度: ',
            {
                xtype: 'combo',
                width: 60,
                hiddenId: 'validation',
                hiddenName: 'validation',
                triggerAction: 'all',
                mode: 'local',
                store: [[-1, '全部'], [1, '非常好'], [2, '很好'], [3, '稍差']],
                value: -1,
                editable: false,
                listClass: 'x-combo-list-small'
            },
            ' ',
            {
               xtype: 'button',
               text: '查询',
               icon: '../../images/find.png',
               enableToggle: true,
               handler: function(){
                   HaiChuan.isSearch = Ext.get('isSearch').getValue();
                   var o = {
                       isSearch: Ext.get('isSearch').getValue(),
                       city: Ext.get('city').getValue(),
                       validation: Ext.get('validation').getValue(),
                       count: Ext.num(Ext.get('count').getValue(), -1),
                       start: 0, limit: HaiChuan.recordsPerPage
                   };
                   HaiChuan.storeData.baseParams = HaiChuan.storeData.baseParams || {};
                   HaiChuan.storeData.reload({params:o});
               }
            }
        ]
    });
    </s:if>

    (function(){
        HaiChuan.storeData.load({params: {start:0, limit:HaiChuan.recordsPerPage}});
    }).defer(100);

    (function(){
        HaiChuan.panelData.setWidth(Ext.lib.Dom.getViewWidth(true)-10);
        HaiChuan.panelData.render('data-div');
    }).defer(0);

});

//-->
</script>
</head>
<body>

  <form id="searchForm"><div id="search-div" style="margin-top:10px;" class="listmargin"></div></form>
  <hr color="#dcebff" class="listmargin">
  <div id="data-div" class="listmargin"></div>
  <hr color="#dcebff" class="listmargin">
  <br />
  <div style="margin-top:10px;" class="listmargin">
    <p>提示：</p>
    <p style="margin-top:10px;">1. 上面表格所列出的只是部分数据项，导出Excel后，根据完整度的不同，可有下面更多的数据项：</p>
    <p>单位名称 负责人 联系人 电话 传真 移动电话 电子邮件 网址 地址 邮政编码 人员规模 营业执照 注册资金 成立日期 行业类型 企业性质 经营模式 业务区域 客户类别 电话区号 省 市 经营范围 公司简介 法人 客户来源 来源网页 国家</p>
    <p style="margin-top:10px;">2. 您可以购买的最大数目根据数据完整度的不同和您的帐户余额确定，其中完整度为“非常好”的数据是${systemConfigs.amountPerData1}元/条，完整度为“很好”的数据是${systemConfigs.amountPerData2}元/条，完整度为“稍差”的数据是${systemConfigs.amountPerData3}元/条。</p>
  </div>

</body>
</html>
